package start.demo01.datatype;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import org.junit.Test;
import start.demo01.domain.Bean1;
import start.demo01.domain.Bean2;
import start.demo01.domain.Bean3;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDateTime;
import java.util.*;

public class UtilsTrans2 {
    public static List mapTransitionList(Map map) {
        List list = new ArrayList();
        Iterator iter = map.entrySet().iterator(); // 获得map的Iterator
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            list.add(entry.getKey());
            list.add(entry.getValue());
        }
        return list;
    }

    @Test
    public void map2List() {
        Map map = new HashMap();
        map.put("aaa", 11);
        map.put("bbb", "22ss");
        map.put("ccc", "汉字");
        List list = mapTransitionList(map);
        for (int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i) + " ");
        }
    }

    @Test
    public void bean2Map() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Bean1 b1 = new Bean1();
        b1.setName("ds");
        b1.setTime(LocalDateTime.now());
        b1.setThrowException(true);
        b1.setNum(9280914901294834L);
        //Map<String,Object> map;//=new HashMap<>();
        //commons-beanutils-1.9.4
//        Map<String, String> describe = BeanUtils.describe(b1);
//        System.out.println(describe);
//        Map<String, Object> map1 = JSON.parseObject(JSON.toJSONString(b1), new TypeReference<Map<String, Object>>() {
//        });
//        System.out.println("map1" + map1);
//        LocalDateTime time = LocalDateTime.parse((CharSequence) describe.get("time"));
//        System.out.println(time);
//        String num = describe.get("num");
//        System.out.println(num);
    }

    @Test
    public void beanUtils() {
        Bean1 b1 = new Bean1();
        Bean2 b2 = new Bean2();
        Bean3 b3 = new Bean3();
        b2.setName("name");
//        org.springframework.beans.BeanUtils.copyProperties(b2, b1);
//        System.out.println(JSON.toJSONString(b1));
//        b3.setNum(990L);
//        org.springframework.beans.BeanUtils.copyProperties(b3, b1);
//        System.out.println(JSON.toJSONString(b1));
    }

    @Test
    public void t0() {
        String str = "dqwdwqfefew{/////\"\"{}\\{}\\{}\\}";
        str.replace("d","-");
        System.out.println(str);

//        String str="Hello World";
//        System.out.println( str.replace( 'H','W' ) );
//        System.out.println( str.replaceFirst("He", "Wa") );
//        System.out.println( str.replaceAll("He", "Ha") );
    }
}
